#include "DDSSimpleFactory.h"
#include "DDSPublisherImp.h"
#include "DDSPUblishImpStr.h"
#include "DDSPublishNormal.h"
#include "common\Common.h"
#include <QDebug>
iDDSPublisher* DDSSimpleFactory::createPublisher(CreateType type)
{
	switch (type)
	{
	case DDSSimpleFactory::eChannelData:
	{
		return (iDDSPublisher*) new DDSPublisherImp();
	}
	case DDSSimpleFactory::eNormalData:
	{
		return (iDDSPublisher*) new DDSPublishNormal();
	}
	case DDSSimpleFactory::eNormalStrData:
	{
		return (iDDSPublisher*) new DDSPUblishImpStr();
	}
	case DDSSimpleFactory::eFanucData:
	{
		return (iDDSPublisher*) new DDSPublishNormal();
	}
	case DDSSimpleFactory::eFanucStrData:
	{
		return (iDDSPublisher*) new DDSPUblishImpStr();
	}
	case DDSSimpleFactory::eBalluffStrData:
	{
		return (iDDSPublisher*) new DDSPUblishImpStr();
	}
	default:
		break;
	}
	return nullptr;
}

void DDSSimpleFactory::SwitchToObserver(iDDSPublisher* publisher, std::shared_ptr<iObserver<IGTConfig::ChannelData>>& obs, CreateType type)
{
	switch (type)
	{
	case DDSSimpleFactory::eChannelData:
	{
		DDSPublisherImp* p = (DDSPublisherImp*)publisher;
		obs = std::shared_ptr<iObserver<IGTConfig::ChannelData>>(p);
	}
	default:
		break;
	}
}

void DDSSimpleFactory::SwitchToObserver(iDDSPublisher* publisher, std::shared_ptr<iObserver<IGTConfig::NormalChannelData>>& obs, CreateType type)
{
	switch (type)
	{
	case DDSSimpleFactory::eNormalData:
	{
		DDSPublishNormal* p = (DDSPublishNormal*)publisher;
		obs = std::shared_ptr<iObserver<IGTConfig::NormalChannelData>>(p);
		break;
	}
	case DDSSimpleFactory::eNormalStrData:
	{
		DDSPUblishImpStr* p = (DDSPUblishImpStr*)publisher;
		obs = std::shared_ptr<iObserver<IGTConfig::NormalChannelData>>(p);
		break;
	}
	case DDSSimpleFactory::eFanucData:
	{
		DDSPublishNormal* p = (DDSPublishNormal*)publisher;
		obs = std::shared_ptr<iObserver<IGTConfig::NormalChannelData>>(p);
		break;
	}
	case DDSSimpleFactory::eFanucStrData:
	{
		DDSPUblishImpStr* p = (DDSPUblishImpStr*)publisher;
		obs = std::shared_ptr<iObserver<IGTConfig::FanucChannelData>>(p);
		break;
	}
	case DDSSimpleFactory::eBalluffStrData:
	{
		DDSPUblishImpStr* p = (DDSPUblishImpStr*)publisher;
		obs = std::shared_ptr<iObserver<IGTConfig::NormalChannelData>>(p);
		break;
	}
	default:
		break;
	}
}
/*
void MqttSimpleFactory::SwitchToObserver(iMqttPublisher *publisher, std::shared_ptr<iObserver<IGTConfig::FanucChannelData>> &obs)
{
	MqttPublisherFanuc *p = (MqttPublisherFanuc *)publisher;
	obs = std::shared_ptr<iObserver<IGTConfig::FanucChannelData>>(p);
}*/
